Package org.javacommerce.google.handler

Source Code of org.javacommerce.google.handler.AbstractOrderStateChangeNotificationHandler

/**
*
*/
package org.javacommerce.google.handler;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
import org.jdom.Document;
import org.jdom.output.XMLOutputter;

import com.google.checkout.OrderStateChangeNotification;

/**
* @author Michael Blanton (mike@mikeblanton.com)
*/
public abstract class AbstractOrderStateChangeNotificationHandler implements
    NotificationHandler {

  private static final Log LOG = LogFactory.getLog(AbstractNewOrderNotificationHandler.class);

  /* (non-Javadoc)
   * @see org.javacommerce.google.handler.NotificationHandler#handleMessage(java.lang.Object)
   */
  public void handleMessage(Document _message) throws HandlerException {
    try {
      XMLOutputter output = new XMLOutputter();
      StringWriter writer = new StringWriter();
      output.output(_message, writer);
      String xml = writer.toString();
      if (LOG.isDebugEnabled()) {
        LOG.debug("Order State Change Notification received: [" + xml + "]");
      }
      OrderStateChangeNotification notification = (OrderStateChangeNotification) Unmarshaller.unmarshal(OrderStateChangeNotification.class, new StringReader(writer.toString()));
      handleNotification(notification);
    } catch (MarshalException e) {
      throw new HandlerException("Error marshalling XML: " + e.getLocalizedMessage(), e);
    } catch (ValidationException e) {
      throw new HandlerException("Error validating XML: " + e.getLocalizedMessage(), e);
    } catch (IOException e) {
      throw new HandlerException("Error parsing XML: " + e.getLocalizedMessage(), e);
    }
  }
 
  public abstract void handleNotification(OrderStateChangeNotification _notification) throws HandlerException;


}
TOP

Related Classes of org.javacommerce.google.handler.AbstractOrderStateChangeNotificationHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.